//
//  YDTuiGuangTableHeaderView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/12/7.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDTuiGuangTableHeaderView.h"

@interface YDTuiGuangTableHeaderView()
@property (nonatomic , weak) UIView *contentView;
//中间分隔线
@property (nonatomic , weak) UIView *lineView;
//我的用户
@property (nonatomic , weak) UILabel *mineUser;
//用户个数
@property (nonatomic , weak) UILabel *userNumber;
//已赚佣金
@property (nonatomic , weak) UILabel *commission;
//佣金额度
@property (nonatomic , weak) UILabel *commissionNumber;
@end

@implementation YDTuiGuangTableHeaderView


-(void)setDict:(NSDictionary *)dict
{
    _dict = dict;
    //用户个数
    NSString *userNumberString = [NSString stringWithFormat:@"%@" , dict[@"promotionCount"]];
    NSString *ge = [NSString stringWithFormat:@"%@个" , userNumberString];

    NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:ge];
 
    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font12ScreenWRate *LKScreenW] range:NSMakeRange(ge.length - 1, 1)];
    
    self.userNumber.attributedText = attriStr;
    
    
    //佣金
    NSString *profitString = [NSString stringWithFormat:@"%@" , dict[@"promotionProfit"]];
    
    NSString *yuan = [NSString stringWithFormat:@"%@元" , [NSString countNumAndChangeformat:[profitString pz_stringNumberByMultiplyingBy:@"1"]]];
    
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:yuan];
    
    [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font12ScreenWRate *LKScreenW] range:NSMakeRange(yuan.length - 1, 1)];
    self.commissionNumber.attributedText = attri;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = NumberColor(247, 247, 247);
        [self contentView];
        [self lineView];
        [self mineUser];
        [self userNumber];
        [self commission];
        [self commissionNumber];
    }
    return self;
}

+(instancetype)tuiGuangTableHeaderViewWithDataDict:(NSDictionary *)dict
{
    YDTuiGuangTableHeaderView *headerView = [[self alloc] init];
    headerView.dict = dict;
    return headerView;
}
-(UIView *)contentView
{
    if (_contentView == nil) {
        UIView *contentView = [[UIView alloc] init];
        [self addSubview:contentView];
        contentView.backgroundColor = NumberColor(62, 89, 167);
        [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(80)));
            }else{
                make.height.equalTo(@(rate750(80)));
            }
        }];
        _contentView = contentView;
        
    }
    return _contentView;
}
-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = [UIColor clearColor];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self.contentView);
            make.centerX.equalTo(self.contentView);
            make.width.equalTo(@1);
        }];
        _lineView = lineView;
        
    }
    return _lineView;
}
-(UILabel *)mineUser
{
    if (_mineUser == nil) {
        UILabel *mineLabel = [[UILabel alloc] init];
        [self.contentView addSubview:mineLabel];
        mineLabel.backgroundColor = [UIColor clearColor];
        mineLabel.textColor = [UIColor whiteColor];
        mineLabel.textAlignment = NSTextAlignmentCenter;
        mineLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        mineLabel.text = @"我的用户";
        [mineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            make.right.equalTo(self.lineView.mas_left);
            make.bottom.equalTo(self.contentView.mas_centerY);
        }];
        _mineUser = mineLabel;
    }
    return _mineUser;
}
-(UILabel *)userNumber
{
    if (_userNumber == nil) {
        UILabel *userNumber = [[UILabel alloc] init];
        [self.contentView addSubview:userNumber];
        userNumber.backgroundColor = [UIColor clearColor];
        userNumber.textColor = [UIColor whiteColor];
        userNumber.textAlignment = NSTextAlignmentCenter;
        userNumber.font = [UIFont systemFontOfSize:font18ScreenWRate * LKScreenW];
        userNumber.text = @"10个";
        [userNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            make.right.equalTo(self.lineView.mas_left);
            make.top.equalTo(self.contentView.mas_centerY);
        }];
        userNumber.adjustsFontSizeToFitWidth = YES;
        
        _userNumber = userNumber;
    }
    return _userNumber;
}
-(UILabel *)commission
{
    if (_commission == nil) {
        UILabel *commission = [[UILabel alloc] init];
        [self.contentView addSubview:commission];
        commission.backgroundColor = [UIColor clearColor];
        commission.textColor = [UIColor whiteColor];
        commission.textAlignment = NSTextAlignmentCenter;
        commission.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        commission.text = @"已赚佣金";
        [commission mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView);
            make.left.equalTo(self.lineView.mas_right);
            make.bottom.equalTo(self.contentView.mas_centerY);
        }];
        _commission = commission;
    }
    return _commission;
}
-(UILabel *)commissionNumber
{
    if (_commissionNumber == nil) {
        UILabel *commissionNumber = [[UILabel alloc] init];
        [self.contentView addSubview:commissionNumber];
        commissionNumber.backgroundColor = [UIColor clearColor];
        commissionNumber.textColor = [UIColor whiteColor];
        commissionNumber.textAlignment = NSTextAlignmentCenter;
        commissionNumber.font = [UIFont systemFontOfSize:font18ScreenWRate * LKScreenW];
        commissionNumber.text = @"1,000.00元";
        [commissionNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView);
            make.left.equalTo(self.lineView.mas_right);
            make.top.equalTo(self.contentView.mas_centerY);
        }];
        
        commissionNumber.adjustsFontSizeToFitWidth = YES;
        _commissionNumber = commissionNumber;
    }
    return _commissionNumber;
}

@end
